package com.example.stock;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyListViewAdaprer extends BaseAdapter {
	private Context context; // 运行上下文
	private List<Map<String, Object>> listItems; // 数据集合
	private LayoutInflater layoutInflater; // 视图容器

	public MyListViewAdaprer(Context context, List<Map<String, Object>> listItems) {
		this.context = context;
		layoutInflater = LayoutInflater.from(context);
		this.listItems = listItems;
	}

	public final class ListItemView { // 自定义控件集合
		public TextView txt_productName;
		public TextView txt_billQty;
		public TextView txt_readyShipQty;
		public TextView txt_shipQty;
	}

	 /** 
     *获取列数  
     */  
	public int getCount() {
		return 0;
	}

	/** 
     *获取某一位置的数据  
     */ 
	public Object getItem(int arg0) {
		return null;
	}

	/** 
     *获取唯一标识 
     */ 
	public long getItemId(int arg0) {
		return 0;
	}

	/** 
     * android绘制每一列的时候，都会调用这个方法 
     */  
	public View getView(int position, View convertView, ViewGroup parent) {
		ListItemView listItemView = null;
		if(convertView ==  null){
			listItemView = new ListItemView();
			//获取组件布局
			convertView = layoutInflater.inflate(R.layout.product_list_view, null);
			listItemView.txt_productName = (TextView)convertView.findViewById(R.id.productName);
			listItemView.txt_billQty = (TextView)convertView.findViewById(R.id.billQty);
			listItemView.txt_readyShipQty = (TextView)convertView.findViewById(R.id.readyShipQty);
			listItemView.txt_shipQty = (TextView)convertView.findViewById(R.id.shipQty);
			// 这里要注意，是使用的tag来存储数据的。  
            convertView.setTag(listItemView);
		}else{
			listItemView = (ListItemView) convertView.getTag();
		}
		listItemView.txt_productName.setText((String)listItems.get(position).get("productName"));
		listItemView.txt_productName.setText((String)listItems.get(position).get("billQty"));
		listItemView.txt_productName.setText((String)listItems.get(position).get("readyShipQty"));
		listItemView.txt_productName.setText((String)listItems.get(position).get("shipQty"));
		return convertView;
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public List<Map<String, Object>> getListItems() {
		return listItems;
	}

	public void setListItems(List<Map<String, Object>> listItems) {
		this.listItems = listItems;
	}

	public LayoutInflater getListContainer() {
		return layoutInflater;
	}

	public void setListContainer(LayoutInflater layoutInflater) {
		this.layoutInflater = layoutInflater;
	}

}
